package com.google.code.cakedroid.context;
//import packages

import com.google.code.cakedroid.base.BaseContext;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;

/**
 *Version Helper Class
 *@author androidyue
 *Last Modified:2011-12-3   am 11:04:21
 */
public class VersionHelper extends BaseContext {
	
	/**
	 *	constructor with parameters 
	 * @param context   Context object
	 */
	public VersionHelper(Context context) {
		super(context);
	}

	/**
	 * get the current application's version name
	 * @param context   Context object
	 * @param defaultVersion  
	 * @return   current version name
	 */
	public   String getVersion(float defaultVersion){
			 String versionName=defaultVersion+"";
			 PackageManager packManager=context.getPackageManager();
			 try {
				 String packageName=context.getPackageName();
				 //PackageManager.NameNotFoundException    may occurs
				PackageInfo packInfo=packManager.getPackageInfo(packageName, 0);
				versionName=packInfo.versionName;
				return versionName;
			} catch (NameNotFoundException e) {
				e.printStackTrace();
				return versionName;
			}	 
	}
}
